global class InsertHCPChangeHistoryClass{
    
    /*==============================================
    2011-01-7 created by lisiheng
    ===============================================*/
    
    @future
    public static void ApproveMethod(list<id> hidl){
        list<hcp__c> hcpl=[select id,approvaltype__c,comments__c,effectivedate__c,changetoclass1__c,changetoclass2__c,classchangeto3__c,class1__c,class2__c,class3__c   from hcp__c where id in:hidl];
        
        list<HCPChangeHistory__c> insertHistory=new list<HCPChangeHistory__c>();
        for(hcp__c hcp:hcpl){
            if(hcp.approvaltype__c == '新增医护人员'){
                HCPChangeHistory__c HCH = new HCPChangeHistory__c (HCP__c=hcp.Id, 
                                               Name = hcp.approvaltype__c,
                                               Old__c='',
                                               New__c='',
                                               comments__c=hcp.comments__c,
                                               effectivedate__c=hcp.effectivedate__c);
                hcp.Active__c = true;
                insertHistory.add(hch);
            }
            else if(hcp.approvaltype__c == ''||hcp.approvaltype__c==null){
                HCPChangeHistory__c HCH = new HCPChangeHistory__c (HCP__c=hcp.Id, 
                                               Name ='重新激活医护人员',
                                               Old__c='',
                                               New__c='',
                                               comments__c=hcp.comments__c,
                                               effectivedate__c=hcp.effectivedate__c);
                hcp.Active__c = true;
                insertHistory.add(hch);
            }
            else if(hcp.approvaltype__c == '删除医护人员'){
                HCPChangeHistory__c HCH = new HCPChangeHistory__c (HCP__c=hcp.Id, 
                                               Name = hcp.approvaltype__c,
                                               Old__c='',
                                               New__c='',
                                               comments__c=hcp.comments__c,
                                               effectivedate__c=hcp.effectivedate__c);
                hcp.Active__c = false;
                insertHistory.add(hch);
            }
            else if(hcp.approvaltype__c == '改变医护人员级别'){
                HCPChangeHistory__c HCH = new HCPChangeHistory__c (HCP__c=hcp.Id, 
                                               Name = hcp.approvaltype__c,
                                               Old__c=hcp.class1__c + ', ' + hcp.class2__c + ', ' + hcp.class3__c,
                                               New__c=hcp.changetoclass1__c + ', ' + hcp.changetoclass2__c + ', ' + hcp.classchangeto3__c,
                                               comments__c=hcp.comments__c,
                                               effectivedate__c=hcp.effectivedate__c);
                hcp.class1__c = hcp.changetoclass1__c;
                hcp.class2__c = hcp.changetoclass2__c;
                hcp.class3__c = hcp.classchangeto3__c;
                insertHistory.add(hch);
            }
            hcp.approvaltype__c = null;
            hcp.classchangeto3__c = null;
            hcp.changetoclass1__c = null;
            hcp.changetoclass2__c = null;
            hcp.effectivedate__c = null;
            hcp.comments__c = null;
            hcp.approvalstatus__c =null;
        }
        insert insertHistory;
        update hcpl;
          
        
    }
    
    
    @future
    public static void RejectMethod(list<id> rejectl){
        list<hcp__c> hcpl=[select id,approvaltype__c,comments__c,effectivedate__c from hcp__c where id in:rejectl];
        list<HCPChangeHistory__c> insertHistory=new list<HCPChangeHistory__c>();
        for(hcp__c hcp:hcpl){
            HCPChangeHistory__c HCH = new HCPChangeHistory__c (HCP__c=hcp.Id, 
                                               Name = '审批拒绝:'+hcp.approvaltype__c,
                                               Old__c='',
                                               New__c='',
                                               comments__c=hcp.comments__c,
                                               effectivedate__c=date.today());
            insertHistory.add(hch);
            hcp.classchangeto3__c = null;
            hcp.changetoclass1__c = null;
            hcp.changetoclass2__c = null;
            hcp.effectivedate__c = null;
            hcp.comments__c = null;
            hcp.approvalstatus__c=null;
            hcp.approvaltype__c=null;
        }
        update hcpl;
        insert insertHistory;
        
    }
    
    
}